﻿var qingting = {init: function () {
    this.scrollNotice()
}, scrollNotice: function () {
    var a = new iScroll({wrapId: "scrollNotice", id: "scrollNoticeLst", direction: "top", speed: 300, rest: 2000, rollLen: 24});
    var c = baidu("#scrollNoticeLst");
    var b = baidu("#noticeDetail");
    c.mouseenter(function () {
        a.stop()
    }).mouseleave(function () {
        a.play()
    }).delegate("a", "mouseover",function () {
        var d = this.getAttribute("info");
        if (d) {
            b.html(d).show()
        }
    }).delegate("a", "mouseout", function () {
        b.html("").hide()
    })
}, getMsgInfo: function () {
    if (!is_login) {
        return
    }
    var b = 5;

    function a() {
        if (typeof redmsg != "undefined") {
            if (!redmsg || redmsg.length < 1) {
                return
            }
            document.getElementById("mnum").innerHTML = redmsg
        } else {
            if (b > 0) {
                setTimeout(a, 100);
                b--
            }
        }
    }

    a()
}, loadingImg: "/static/image/loading.gif", feedWrap: document.getElementById("feedTabCnt"), toggleFeed: function () {
    var a = this.feedWrap;
    baidu.dom(a).delegate("a", "click", function (g) {
        g = baidu.event(g || window.event);
        var h = baidu.dom(g.target);
        var c = h.hasClass("btnShowFeed");
        var f = h.hasClass("btnCloseFeed");
        if (!(c || f)) {
            return
        }
        g.preventDefault();
        if (c) {
            var d = h.parent().parent();
            var b = d.next();
            d.hide();
            b.show()
        } else {
            if (f) {
                var b = h.parent().parent();
                var d = b.prev();
                d.show();
                b.hide()
            }
        }
    })
}, toggFeedPic: function () {
    var b = this;
    var a = b.feedWrap;
    baidu.dom(a).delegate("span.picLayer", "click", function (g) {
        g = baidu.event(g || window.event);
        g.preventDefault();
        var j = baidu.dom(g.target), c = g.target.tagName.toUpperCase();
        var i = j.parent();
        var h = c == "IMG" ? j : i.find("img").eq(0);
        var f = i.next();
        i.hide();
        var d = f.attr("orgsrc");
        if (d) {
            b.setBigWidth(f, d);
            f.attr("src", d);
            f.removeAttr("orgsrc")
        }
        f.show()
    });
    baidu.dom(a).delegate("img.oneBigPic", "click", function (d) {
        d = baidu.event(d || window.event);
        d.preventDefault();
        var c = baidu.dom(d.target);
        var f = c.prev();
        c.hide();
        f.show()
    })
}, toggPicLst: function () {
    var b = this;
    var a = b.feedWrap;
    baidu.dom(a).delegate("li.picLayer", "click", function (h) {
        h = baidu.event(h || window.event);
        h.preventDefault();
        var d = baidu.dom(h.target), m = h.target.tagName.toUpperCase();
        var l = d.parent();
        var i = l.parent();
        var f = m == "IMG" ? d : l.find("img").eq(0);
        var k = i.children("li");
        var j = baidu.dom("#feedBigPic_" + f.attr("feedindex"));
        if (l.hasClass("on")) {
            j.parent().hide();
            l.removeClass("on")
        } else {
            var g = f.attr("src");
            var c = spacePicPath + g.substr(g.lastIndexOf("/") + 1);
            b.setBigWidth(j, c);
            j.attr("src", c);
            j.css("width", "auto");
            j.parent().show()
        }
    });
    baidu.dom(a).delegate("img.feedBigPic", "click", function (f) {
        f = baidu.event(f || window.event);
        f.preventDefault();
        var c = baidu.dom(f.target), d = baidu.dom("#feedpicLst_" + c.attr("feedindex")).children("li");
        d.removeClass("on");
        c.parent().hide()
    })
}, setBigWidth: function (a, c) {
    var b = new Image();
    b.src = c;
    b.onload = function () {
        var d = this.width, e = 820;
        if (d > e) {
            a.width(e)
        }
    }
}, initFeed: function () {
    var a = this.feedWrap;
    if (!this.feedWrap) {
        return
    }
    this.setPage();
    this.toggleFeed();
    this.toggPicLst();
    this.toggFeedPic();
    this.bindShowMore();
    this.checkVoiceNew();
    this.scrollBtnGotop()
}, scrollBtnGotop: function () {
    var a = document.getElementById("btnGoTop");
    var b = body();
    if (b.documentHeight <= b.viewHeight) {
        a.style.display = "none";
        return
    }
    baidu.dom(window).scroll(function (f) {
        var d = body();
        var c = d.viewHeight;
        if (d.scrollTop <= 100) {
            a.style.display = "none";
            return
        }
        var g = c + d.scrollTop - 350;
        a.style.display = "block";
        a.style.top = g + "px"
    })
}, setPage: function () {
    var a = "feedPage", b = document.getElementById(a);
    if (!b) {
        return
    }
    pageIn.init({url: b.getAttribute("pageurl"), curPage: b.getAttribute("curpage"), totalPage: b.getAttribute("totalpage"), id: a})
}, bindShowMore: function () {
    var d = this, a = baidu("#showMoreFeed"), b = baidu("#feedPage");
    if (!a[0]) {
        return
    } else {
        b.hide()
    }
    var c = 0;
    var e = function (g) {
        g.preventDefault();
        d._showLoading(a);
        if (typeof(feedListAry) == "undefined" || feedListAry.length <= 0) {
            return
        }
        var f = 10;
        if (f > feedListAry.length) {
            f = feedListAry.length
        }
        c += 10;
        d.addVoiceToPage(feedListAry.splice(0, f), a, c);
        d._removeLoading(a);
        if (feedListAry.length <= 0) {
            a.remove();
            if (b) {
                b.show()
            }
        }
    };
    a.bind("click", e)
}, addVoiceToPage: function (j, g, d) {
    var a = j.length;
    var h = [];
    while (a > 0) {
        var e = j.shift();
        var c = [];
        c.push('<dl class="feedList">');
        c.push("<dt>用户：" + e.user + '<span class="feedtime">' + e.time + "</span></dt>");
        c.push('<dd class="feedcnt">' + e.feed);
        if (e.feedAll) {
            c.push('<p class="infolink"><a href="#" class="btnShowFeed">显示全部</a></p></dd>');
            c.push('<dd class="feedcnt expandfeed">');
            c.push(e.feedAll);
            c.push('<p class="infolink"><a href="#" class="btnCloseFeed">收起</a></p>')
        }
        c.push("</dd>");
        if (e.pic) {
            var f = e.pic;
            var k = f.length;
            c.push('<dd class="clear feedpic">');
            if (k == 1) {
                c.push('<span class="picLayer" name="feedPic">');
                c.push('<img src="' + spacePicAbpath + f[0] + '.jpg"  onload="formatPic(this,150,150)"/>');
                c.push('<span class="icoMagnify" name="feddManify"></span></span>');
                c.push('<img class="oneBigPic" src="" orgsrc="' + spacePicPath + f[0] + '.jpg" alt="" style="display:none;"/>')
            } else {
                if (k > 1) {
                    c.push('<ul class="feedpicLst clear" id="feedpicLst_' + d + '">');
                    for (var b = 0; b < k; b++) {
                        c.push('<li class="picLayer"><img src="' + spacePicAbpath + f[b] + '.jpg" alt="" feedindex="' + d + '"/><span class="icoMagnify"></span></li>')
                    }
                    c.push("</ul>");
                    c.push('<p class="viewBigPic" style="display:none;"><img src="" alt="" class="feedBigPic" id="feedBigPic_' + d + '" feedindex="' + d + '"/></p>')
                }
            }
            d++;
            c.push("</dd>")
        }
        if (e.writeback) {
            c.push('<dd class="writeback"><h3 class="b_tit">百度倾听回复：</h3>' + e.writeback + "</dd>")
        }
        c.push("</dl>");
        h.push(c.join(""));
        a--
    }
    baidu(h.join("")).insertBefore(g)
}, _showLoading: function (c) {
    if (!c) {
        return
    }
    var b = this;
    var a = '<p class="msgBar newmsg"><img src="' + b.loadingImg + '"/><span>正在加载，耐心等待一下吧...</span></p>';
    baidu.dom(a).insertAfter(c);
    c.hide()
}, _removeLoading: function (a) {
    var b = a.next();
    b.remove();
    a.show()
}, loadVoiceNew: function () {
    var d = this, c = baidu("#newVoiceTip"), b = document.getElementById("refreshTime").value, a = document.getElementById("pid").value;
    d._showLoading(c);
    baidu.ajax("/ajax_shengyin?type=2&last_refresh_time=" + b + "&pid=" + a + "&rand=" + Math.random(), {success: function (e) {
        if (typeof(e) == "string") {
            e = baidu.json.parse(e)
        }
        var f = e.newMsgCount;
        if (!f) {
            return
        }
        if (f >= 100) {
            window.location.reload();
            return
        }
        d.addVoiceToPage(e.feedList, c);
        d._removeLoading(c);
        c.remove()
    }, error: function () {
        baidu("#newVoiceLink").html("加载失败，请重新点击查看！");
        d._removeLoading(c);
        c.show()
    }})
}, checkVoiceNew: function () {
    if (!document.getElementById("feedPage")) {
        return
    }
    var g = 20000, d = 0;
    var b = baidu.dom(this.feedWrap), a = false, f = document.getElementById("refreshTime").value, c = document.getElementById("pid").value;

    function e() {
        baidu.ajax("/ajax_shengyin?type=1&last_refresh_time=" + f + "&pid=" + c + "&rand=" + Math.random(), {success: function (i) {
            if (typeof(i) == "string") {
                i = baidu.json.parse(i)
            }
            if (i.newMsgCount) {
                b.prepend('<p class="msgBar newMsg" id="newVoiceTip"><a href="#" onclick="qingting.loadVoiceNew();" id="newVoiceLink">有新消息，点击查看</a></p>');
                a = true
            }
        }, complete: function () {
            if (a) {
                return
            }
            if (++d <= 50) {
                g += 3000
            } else {
                return
            }
            h = window.setTimeout(e, g)
        }})
    }

    var h = window.setTimeout(e, g)
}, initForm: function () {
    if (!document.getElementById("tagJianyiCnt")) {
        return
    }
    var b = document.getElementById("pid").value;
    var d = this;
    if (b == "1") {
        webmaster.init()
    } else {
        var c = baidu.dom("#formJianyi");
        var a = baidu.dom("#formContent");
        a.attr("defval", a.val());
        c.vaildForm({fields: {"#formContent": {required: true, regExp: "len", emptyMsg: "发送内容不能为空哦", errMsg: "发送内容不能超过500字哦"}, "#formEmail": {regExp: "email", errMsg: "请输入正确邮箱地址"}, "#formPhone": {regExp: "phone", errMsg: "请输入正确手机号码"}}})
    }
    d._setFormBrowser();
    d._setFormOs()
}, _setFormOs: function () {
    var f = ["Android", "Ipad", "Iphone", "Macintosh", "Windows", "X11", "Linux"];
    var e = document.getElementById("formOs");
    var b;
    for (var d = 0, a = f.length; d < a; d++) {
        var c = f[d];
        if (baidu.platform["is" + c]) {
            if (c == "Windows") {
                c += " " + baidu.platform.windows
            }
            e.value = c;
            break
        }
    }
}, _setFormBrowser: function () {
    var e = ["maxthon", "se360", "QQ", "TencentTraveler", "sogou", "theworld", "baidu", "chrome", "firefox", "ie", "safari", "opera"];
    var f = document.getElementById("formBrowser");
    var b;
    for (var d = 0, a = e.length; d < a; d++) {
        var c = e[d];
        b = baidu.browser[c];
        if (b) {
            if (typeof(b) != "boolean") {
                c += " " + b
            }
            f.value = c;
            break
        }
    }
}};
qingting.init();
qingting.initFeed();
qingting.initForm();